package beerAir;

import java.util.ArrayList;
import java.util.List;
import javax.persistence.*;

public class AirportController {
	
	public List<Airport> getAllAirports(){
		
		EntityManagerFactory factory;
		EntityManager manager;
		
		factory= Persistence.createEntityManagerFactory("BeerAir");
		manager = factory.createEntityManager();
		List<Airport> la= new ArrayList<Airport>();
		try{
		la=manager.createQuery("SELECT a FROM Airport a", Airport.class).getResultList();
		}catch(Exception e){
			return null;
		}
		return la;
	}
	
	public List<String> getAllCities(){
		List<Airport> la = getAllAirports();
		List<String> lc = new ArrayList<String>();
		for (Airport temp : la) {
			lc.add(temp.getCity());
		}
		return lc;
	}
	
	public List<String> getAllIcaoCode(){
		List<Airport> la = getAllAirports();
		List<String> lc = new ArrayList<String>();
		for (Airport temp : la) {
			lc.add(temp.getIcaoCode());
		}
		return lc;
	}
}
